import time
from common.base_s import Base, By, get_driver
from page.login_page import LoginPage


class CheckoutPage(Base):
    # 结算页面
    login_url = "http://localhost:8080/ecshop/flow.php?step=checkout"

    # 点击用户中心
    def user_center(self):
        self.click((By.XPATH, '/html/body/div[1]/div/div[2]/div[1]/a'))

    # 点击我的订单
    def my_order(self):
        self.click((By.XPATH, '/html/body/div[6]/div[1]/div/div/div/div/a[3]'))

    # 点击再次购买
    def buy_again(self):
        self.click((By.XPATH, '/html/body/div[6]/div[2]/div/div/div/table/tbody/tr[1]/td[5]/a'))

    # 点击结算
    def settlement(self):
        self.click((By.XPATH, '/html/body/div[6]/div[1]/table/tbody/tr/td[2]/a/img'))

    # 支付方式 余额支付
    def balance_payment(self):
        self.click((By.XPATH, '//*[@id="paymentTable"]/tbody/tr[2]/td[1]/input'))

    # 支付方式 银行汇款
    def bank_remittance(self):
        self.click((By.XPATH, '//*[@id="paymentTable"]/tbody/tr[3]/td[1]/input'))

    # 提交订单
    def submit_an_order(self):
        self.click((By.XPATH, '//*[@id="theForm"]/div[15]/div[2]/input[1]'))

    # 获取生成订单号码
    def generate_order_number(self):
        return self.text((By.XPATH, '/html/body/div[6]/div/h6/font'))

    # 获取生成订单的快递方式
    def generate_order_express(self):
        return self.text((By.XPATH, '/html/body/div[6]/div/table/tbody/tr[1]/td/strong[1]'))

    # 获取生成订单的金额
    def generate_order_money(self):
        return self.text((By.XPATH, '/html/body/div[6]/div/table/tbody/tr[1]/td/strong[3]'))

if __name__ == '__main__':
    # 打开浏览器，请求目标网址

    Personal = CheckoutPage(get_driver())  # 实例化浏览器
    Personal.login_user()  # 实现登录

    Personal.user_center()  # 点击用户中心

    time.sleep(3)
    # 点击我的订单
    Personal.my_order()
    time.sleep(3)
    # 点击再次购买
    Personal.buy_again()


    # 结算
    Personal.settlement()
    # 选购物方式 银行汇款
    Personal.bank_remittance()
    # 提交
    Personal.submit_an_order()

    print(Personal.generate_order_express())  # 打印生成订单的相关信息
    print(Personal.generate_order_number())
    print(Personal.generate_order_money())

